/*
' Copyright (c) 2010 DotNetNuke Corporation
'  All rights reserved.
' 
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
' DEALINGS IN THE SOFTWARE.
' 
*/

using System;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Entities.Modules;
using DotNetNuke.UI.Skins.Controls;
using DotNetNuke.Common;

namespace DotNetNuke.Modules.FB_FanGate {

    /// -----------------------------------------------------------------------------
    /// <summary>
    /// The EditFB_FanGate class is used to manage content
    /// </summary>
    /// -----------------------------------------------------------------------------
    public partial class Edit : FB_FanGateModuleBase {

        #region Event Handlers

        override protected void OnInit(EventArgs e) {
            InitializeComponent();
            base.OnInit(e);
            lnkSave.Click += OnSaveClick;
            lnkCancel.Click += OnCancelClick;
        }

        private void InitializeComponent() {
            this.Load += new System.EventHandler(this.Page_Load);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// Page_Load runs when the control is loaded
        /// </summary>
        /// -----------------------------------------------------------------------------
        private void Page_Load(object sender, System.EventArgs e) {
            try {
                //Implement your edit logic for your module
                string IsFanText = string.Empty;
                if (Settings.ContainsKey("IsFanText")) {
                    IsFanText = Settings["IsFanText"].ToString();
                }
                string NotFanText = string.Empty;
                if (Settings.ContainsKey("NotFanText")) {
                    NotFanText = Settings["NotFanText"].ToString();
                }
                rteLikes.Text = IsFanText;
                rteNotLike.Text = NotFanText;
            } catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
        protected void OnCancelClick(object sender, EventArgs e) {
            Response.Redirect(Globals.NavigateURL(), true);
        }
        protected void OnSaveClick(object sender, EventArgs e) {
            try {
                //update summary settings
                var objModules = new ModuleController();
                objModules.UpdateTabModuleSetting(TabModuleId, "IsFanText", rteLikes.Text);
                objModules.UpdateTabModuleSetting(TabModuleId, "NotFanText", rteNotLike.Text);

            } catch (Exception exc) {
                Exceptions.LogException(exc);
                UI.Skins.Skin.AddModuleMessage(Page, "Error occurred: ", exc.Message, ModuleMessage.ModuleMessageType.RedError);
                return;
            }

            Response.Redirect(Globals.NavigateURL(), true);
        }
        #endregion

    }

}